package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.qf.pojo.Cars;
import com.qf.pojo.Msg;
import com.qf.service.CarsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/car")
public class CarsController {
    @Autowired
    private CarsService carsService;

    @RequestMapping("/car.do")
    @ResponseBody//根据cid查询单个car
    public Msg selcarById(int cid){
        Cars cars = carsService.selectOneByCid(cid);
        Msg<Object> msg = new Msg<>();
        msg.setCode(1);
        msg.setData(cars);
        return msg;
    }

    @RequestMapping("/cars.do")
    @ResponseBody//根据cid查询car
    public Msg selcityById(int getid){
        List<Cars> carsList = carsService.selectcarByCid(getid);
        Msg m = new Msg();
        m.setCode(1);
        m.setData(carsList);
        return m;
    }
    @GetMapping//查询
    @ResponseBody
    public Msg<Cars> all(int page, int limit) {
        PageHelper.startPage(page, limit);
        List<Cars> clist = carsService.selectAll();
        Msg<Cars> m = new Msg<>();
        m.setCount(10);
        m.setData(clist);
        return m;
    }

    @PostMapping//增加
    public String add() {

        return "";
    }

    @DeleteMapping//删除
    @ResponseBody
    public void delete( int cid) {
        int res = carsService.deleOne(cid);

    }

    @PutMapping//修改
    public String update() {

        return "";
    }
}
